
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>4.1 Kubernetes 网络 · Kubernetes - 痴者工良</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="痴者工良">
        
        
    
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    


    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="2.endpoint.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://www.whuanle.cn" target="_blank" class="custom-link">痴者工良的博客</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    文档说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../1.basic/">
            
                <a href="../1.basic/">
            
                    
                    1.基础知识
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../1.basic/">
            
                <a href="../1.basic/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../1.basic/1.docker.html">
            
                <a href="../1.basic/1.docker.html">
            
                    
                    1.1 说透 Docker：基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../1.basic/2.virtual.html">
            
                <a href="../1.basic/2.virtual.html">
            
                    
                    1.2 说透 Docker： 虚拟化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../1.basic/3.docker_network.html">
            
                <a href="../1.basic/3.docker_network.html">
            
                    
                    1.3 了解 Docker 网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../1.basic/4.pod_docker.html">
            
                <a href="../1.basic/4.pod_docker.html">
            
                    
                    1.4 Docker 和 Pod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../1.basic/5.k8s.html">
            
                <a href="../1.basic/5.k8s.html">
            
                    
                    1.5 K8S入门基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../2.deploy/">
            
                <a href="../2.deploy/">
            
                    
                    2.部署和配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../2.deploy/2.deploy.md">
            
                <span>
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../2.deploy/1.minikube.html">
            
                <a href="../2.deploy/1.minikube.html">
            
                    
                    2.1 使用 Minikube 部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../2.deploy/2.kubeadm.html">
            
                <a href="../2.deploy/2.kubeadm.html">
            
                    
                    2.2 使用 kubeadm 部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../2.deploy/3.kubeadm_ckad.html">
            
                <a href="../2.deploy/3.kubeadm_ckad.html">
            
                    
                    2.3 CKAD认证中的部署教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../2.deploy/4.kubeadm_proxy.html">
            
                <a href="../2.deploy/4.kubeadm_proxy.html">
            
                    
                    2.4 国内代理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../2.deploy/5.dashboard.html">
            
                <a href="../2.deploy/5.dashboard.html">
            
                    
                    2.5 Dashboard
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../3.pod/">
            
                <a href="../3.pod/">
            
                    
                    3.Pod部署和调度
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../3.pod/">
            
                <a href="../3.pod/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../3.pod/1.pod.html">
            
                <a href="../3.pod/1.pod.html">
            
                    
                    3.1 Pod
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../3.pod/2.deployment.html">
            
                <a href="../3.pod/2.deployment.html">
            
                    
                    3.2 Deployment部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../3.pod/3.replica.html">
            
                <a href="../3.pod/3.replica.html">
            
                    
                    3.3 副本集(ReplicaSet)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../3.pod/4.pod_network.html">
            
                <a href="../3.pod/4.pod_network.html">
            
                    
                    3.34 Pod 端口映射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../3.pod/5.update.html">
            
                <a href="../3.pod/5.update.html">
            
                    
                    3.5 Pod 升级、回滚
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../3.pod/6.scale.html">
            
                <a href="../3.pod/6.scale.html">
            
                    
                    3.6 Pod 缩放
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../3.pod/7.lable.html">
            
                <a href="../3.pod/7.lable.html">
            
                    
                    3.7.Pod 标签
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../3.pod/8.schedule.html">
            
                <a href="../3.pod/8.schedule.html">
            
                    
                    3.8 Pod 调度
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../3.pod/9.jobs_cronjobs.html">
            
                <a href="../3.pod/9.jobs_cronjobs.html">
            
                    
                    3.9 Jobs、CronJobs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    4.Kubernetes 网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="./">
            
                <a href="./">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.2" data-path="1.network.html">
            
                <a href="1.network.html">
            
                    
                    4.1 Kubernetes 网络
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="2.endpoint.html">
            
                <a href="2.endpoint.html">
            
                    
                    4.2 Endpoint
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="3.ingress.html">
            
                <a href="3.ingress.html">
            
                    
                    4.3 ingress
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="4.discovery.html">
            
                <a href="4.discovery.html">
            
                    
                    4.4 服务发现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../5.volumes/">
            
                <a href="../5.volumes/">
            
                    
                    5.volumes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../5.volumes/">
            
                <a href="../5.volumes/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../5.volumes/1.volumes.html">
            
                <a href="../5.volumes/1.volumes.html">
            
                    
                    5.1 卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../5.volumes/2.secret_configmap.html">
            
                <a href="../5.volumes/2.secret_configmap.html">
            
                    
                    5.2 secret 和 ConfigMap 卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../5.volumes/3.nfts.html">
            
                <a href="../5.volumes/3.nfts.html">
            
                    
                    5.3 NFS卷
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../5.volumes/4.pv_pvc.html">
            
                <a href="../5.volumes/4.pv_pvc.html">
            
                    
                    5.4 持久化卷
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../6.api_safe/">
            
                <a href="../6.api_safe/">
            
                    
                    6.API 和 安全
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../6.api_safe/">
            
                <a href="../6.api_safe/">
            
                    
                    导读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../7.health/">
            
                <a href="../7.health/">
            
                    
                    7.维护和故障排除
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../8.health/README.md">
            
                <span>
            
                    
                    导读
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../k8s.html">
            
                <a href="../k8s.html">
            
                    
                    Kubernetes 命令概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../ckad.html">
            
                <a href="../ckad.html">
            
                    
                    CKAD 认证帮助
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >4.1 Kubernetes 网络</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#41-kubernetes-&#x7F51;&#x7EDC;"><b></b>4.1 Kubernetes &#x7F51;&#x7EDC;</a></li><ul><ul><li><span class="title-icon "></span><a href="#&#x5BFC;&#x8BFB;"><b></b>&#x5BFC;&#x8BFB;</a></li></ul><li><span class="title-icon "></span><a href="#kubernetes-&#x7F51;&#x7EDC;"><b></b>Kubernetes &#x7F51;&#x7EDC;</a></li><ul><li><span class="title-icon "></span><a href="#kubernetes-&#x7F51;&#x7EDC;&#x6A21;&#x578B;"><b></b>Kubernetes &#x7F51;&#x7EDC;&#x6A21;&#x578B;</a></li></ul><li><span class="title-icon "></span><a href="#service"><b></b>Service</a></li><ul><li><span class="title-icon "></span><a href="#&#x6CA1;&#x6709;-service-&#x65F6;"><b></b>&#x6CA1;&#x6709; Service &#x65F6;</a></li><li><span class="title-icon "></span><a href="#service-&#x7684;&#x5B9A;&#x4E49;&#x548C;&#x521B;&#x5EFA;"><b></b>Service &#x7684;&#x5B9A;&#x4E49;&#x548C;&#x521B;&#x5EFA;</a></li><li><span class="title-icon "></span><a href="#service-&#x5916;&#x90E8;&#x670D;&#x52A1;&#x7C7B;&#x578B;"><b></b>Service &#x5916;&#x90E8;&#x670D;&#x52A1;&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#&#x914D;&#x7F6E;-servicetype-&#x516C;&#x5F00;-service"><b></b>&#x914D;&#x7F6E; ServiceType &#x516C;&#x5F00; Service</a></li><li><span class="title-icon "></span><a href="#loadbalancer"><b></b>LoadBalancer</a></li><li><span class="title-icon "></span><a href="#service-&#x5982;&#x4F55;&#x9009;&#x62E9;-pod"><b></b>Service &#x5982;&#x4F55;&#x9009;&#x62E9; Pod</a></li><li><span class="title-icon "></span><a href="#kube-proxy-&#x4E09;&#x79CD;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;"><b></b>kube-proxy &#x4E09;&#x79CD;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;</a></li><li><span class="title-icon "></span><a href="#service-&#x66B4;&#x9732;&#x591A;&#x7AEF;&#x53E3;"><b></b>Service &#x66B4;&#x9732;&#x591A;&#x7AEF;&#x53E3;</a></li></ul></ul></ul></div><h1 id="41-kubernetes-&#x7F51;&#x7EDC;"><a name="41-kubernetes-&#x7F51;&#x7EDC;" class="anchor-navigation-ex-anchor" href="#41-kubernetes-&#x7F51;&#x7EDC;"><i class="fa fa-link" aria-hidden="true"></i></a>4.1 Kubernetes &#x7F51;&#x7EDC;</h1>
<h3 id="&#x5BFC;&#x8BFB;"><a name="&#x5BFC;&#x8BFB;" class="anchor-navigation-ex-anchor" href="#&#x5BFC;&#x8BFB;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5BFC;&#x8BFB;</h3>
<p>&#x672C;&#x7AE0;&#x5185;&#x5BB9;&#x4E3B;&#x8981;&#x8BB2;&#x89E3; Kubernetes  &#x4E2D;&#x7684;&#x7F51;&#x7EDC;&#x548C; Service &#x5BF9;&#x8C61;&#xFF0C;&#x4F5C;&#x4E3A; Kubernetes &#x7684;&#x6838;&#x5FC3;&#x5185;&#x5BB9;&#xFF0C; Kubernetes &#x7F51;&#x7EDC;&#x6D89;&#x53CA;&#x5230;&#x4E86;&#x5F88;&#x591A;&#x4E1C;&#x897F;&#xFF0C;&#x8BA1;&#x7B97;&#x673A;&#x7F51;&#x7EDC;&#x539F;&#x7406;&#x3001;Linux &#x7F51;&#x7EDC;&#x3001;&#x5206;&#x5E03;&#x5F0F;&#x7F51;&#x7EDC;&#x7406;&#x8BBA;&#x7B49;&#xFF0C;&#x9650;&#x4E8E;&#x4E2A;&#x4EBA;&#x6C34;&#x5E73;&#x548C;&#x7BC7;&#x5E45;&#xFF0C;&#x5C06;&#x4E0D;&#x4F1A;&#x6DF1;&#x5165;&#x8BB2;&#x89E3;&#x8FD9;&#x4E9B;&#x7EC6;&#x8282;&#x3002;</p>
<h2 id="kubernetes-&#x7F51;&#x7EDC;"><a name="kubernetes-&#x7F51;&#x7EDC;" class="anchor-navigation-ex-anchor" href="#kubernetes-&#x7F51;&#x7EDC;"><i class="fa fa-link" aria-hidden="true"></i></a>Kubernetes &#x7F51;&#x7EDC;</h2>
<h3 id="kubernetes-&#x7F51;&#x7EDC;&#x6A21;&#x578B;"><a name="kubernetes-&#x7F51;&#x7EDC;&#x6A21;&#x578B;" class="anchor-navigation-ex-anchor" href="#kubernetes-&#x7F51;&#x7EDC;&#x6A21;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>Kubernetes &#x7F51;&#x7EDC;&#x6A21;&#x578B;</h3>
<p>&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x8981;&#x77E5;&#x9053; Kubernetes &#x4E2D;&#x7684;&#x7F51;&#x7EDC;&#x53EF;&#x4EE5;&#x89E3;&#x51B3;&#x4EC0;&#x4E48;&#x95EE;&#x9898;&#xFF0C;&#x5728; Kuberbnetes &#x5B98;&#x65B9;&#x6587;&#x6863;&#x4E2D;&#xFF0C;&#x6E05;&#x6670;&#x5730;&#x5217;&#x4E3E;&#x4E86; Kubernetes &#x7F51;&#x7EDC;&#x7684;&#x529F;&#x80FD;&#xFF1A;</p>
<ol>
<li>&#x9AD8;&#x5EA6;&#x8026;&#x5408;&#x7684;&#x5BB9;&#x5668;&#x95F4;&#x901A;&#x4FE1;&#xFF1A;&#x8FD9;&#x4E2A;&#x5DF2;&#x7ECF;&#x88AB; Pods &#x548C; <code>localhost</code> &#x901A;&#x4FE1;&#x89E3;&#x51B3;&#x4E86;&#x3002;</li>
<li>Pod &#x95F4;&#x901A;&#x4FE1;&#xFF1B;</li>
<li>Pod &#x548C;&#x670D;&#x52A1;&#x95F4;&#x901A;&#x4FE1;&#xFF1B;</li>
<li>&#x5916;&#x90E8;&#x548C;&#x670D;&#x52A1;&#x95F4;&#x901A;&#x4FE1;&#xFF1B;</li>
</ol>
<blockquote>
<p>&#x8FD9;&#x91CC;&#x7684;&#x670D;&#x52A1;&#xFF0C;&#x6307;&#x7684;&#x662F; Service &#x5BF9;&#x8C61;&#x3002;</p>
</blockquote>
<p>&#x800C; Kubernetes &#x672C;&#x8EAB;&#x7684;&#x7F51;&#x7EDC;&#x670D;&#x52A1;&#x81EA;&#x5E26;&#x4E86;&#x8FD9;&#x4E9B;&#x529F;&#x80FD;&#xFF1A;</p>
<ul>
<li>NAT: &#x7F51;&#x7EDC;&#x5730;&#x5740;&#x8F6C;&#x6362;</li>
<li>Source NAT: &#x66FF;&#x6362;&#x6570;&#x636E;&#x5305;&#x7684;&#x6E90; IP, &#x901A;&#x5E38;&#x4E3A;&#x8282;&#x70B9;&#x7684; IP</li>
<li>Destination NAT: &#x66FF;&#x6362;&#x6570;&#x636E;&#x5305;&#x7684;&#x76EE;&#x7684; IP, &#x901A;&#x5E38;&#x4E3A; Pod &#x7684; IP</li>
<li>VIP: &#x4E00;&#x4E2A;&#x865A;&#x62DF; IP, &#x4F8B;&#x5982;&#x5206;&#x914D;&#x7ED9;&#x6BCF;&#x4E2A; Kubernetes Service &#x7684; IP</li>
<li>Kube-proxy: &#x4E00;&#x4E2A;&#x7F51;&#x7EDC;&#x5B88;&#x62A4;&#x7A0B;&#x5E8F;&#xFF0C;&#x5728;&#x6BCF;&#x4E2A;&#x8282;&#x70B9;&#x4E0A;&#x534F;&#x8C03; Service VIP &#x7BA1;&#x7406;</li>
</ul>
<blockquote>
<p>&#x53EF;&#x53C2;&#x8003; <a href="https://kubernetes.io/zh/docs/tutorials/services/source-ip/" target="_blank">https://kubernetes.io/zh/docs/tutorials/services/source-ip/</a></p>
</blockquote>
<h4 id="pod-ip-&#x4ECE;&#x54EA;&#x91CC;&#x6765;"><a name="pod-ip-&#x4ECE;&#x54EA;&#x91CC;&#x6765;" class="anchor-navigation-ex-anchor" href="#pod-ip-&#x4ECE;&#x54EA;&#x91CC;&#x6765;"><i class="fa fa-link" aria-hidden="true"></i></a>Pod IP &#x4ECE;&#x54EA;&#x91CC;&#x6765;</h4>
<p>&#x8FD8;&#x8BB0;&#x5F97;&#x5728; <a href="../1.basic/3.docker_network.html">1.3 &#x7AE0; Docker &#x7F51;&#x7EDC;</a> &#x4E2D;&#x4ECB;&#x7ECD;&#x7684; container &#x7F51;&#x7EDC;&#x4E48;&#xFF1F;&#x591A;&#x4E2A;&#x5BB9;&#x5668;&#x5171;&#x4EAB;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#x7684;&#x7F51;&#x7EDC;&#x63A5;&#x53E3;&#xFF0C;&#x5B9E;&#x73B0;&#x591A;&#x4E2A;&#x5BB9;&#x5668;&#x5171;&#x4EAB;&#x7F51;&#x7EDC;&#x3001;&#x540C;&#x4E00;&#x4E2A; IP&#x3001;&#x540C;&#x4E00;&#x4E2A; hostname&#x3002; Pod &#x5185;&#x591A;&#x5BB9;&#x5668;&#x5171;&#x4EAB;&#x7F51;&#x7EDC;&#x5C31;&#x662F;&#x8FD9;&#x6837;&#x521B;&#x5EFA;&#x7684;&#xFF0C;<strong>Pod &#x7684; IP &#x662F; Docker &#x521B;&#x5EFA;&#x548C;&#x5206;&#x914D;&#x7684;&#x5BB9;&#x5668; IP</strong>&#xFF0C;<strong>&#x8FD9;&#x4E2A; IP &#x662F;&#x5E26;&#x865A;&#x62DF;&#x7F51;&#x5361;&#x7684;</strong>&#xFF0C;&#x56E0;&#x6B64;<strong>&#x8FD9;&#x4E2A; IP &#x662F;&#x53EF;&#x4EE5;&#x88AB; ping &#x7684;</strong>&#xFF0C;&#x4E0E;&#x6B64;&#x540C;&#x65F6;&#xFF0C;<strong>&#x8FD9;&#x4E2A; IP &#x53EA;&#x80FD;&#x5728;&#x5F53;&#x524D;&#x8282;&#x70B9;&#x4E2D;&#x88AB;&#x8BBF;&#x95EE;</strong>&#x3002;</p>
<p>&#x9996;&#x5148;&#x521B;&#x5EFA; Pod &#x65F6;&#xFF0C;Pod &#x4F1A;&#x542F;&#x52A8;&#x4E00;&#x4E2A; pause &#x5BB9;&#x5668;&#xFF0C;&#x8FD9;&#x4E2A;&#x5BB9;&#x5668;&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x865A;&#x62DF;&#x7F51;&#x5361;&#xFF0C;&#x5E76;&#x88AB; Docker &#x5206;&#x914D; IP&#xFF0C;&#x63A5;&#x7740; Pod &#x7684;&#x5BB9;&#x5668;&#x4F1A;&#x4F7F;&#x7528; container &#x7F51;&#x7EDC;&#x6A21;&#x5F0F;&#x8FDE;&#x63A5;&#x5230;&#x8FD9;&#x4E2A; pause &#x5BB9;&#x5668;&#x4E2D;&#xFF0C;pause &#x5BB9;&#x5668;&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;&#x8DDF; Pod &#x7684;&#x751F;&#x547D;&#x5468;&#x671F;&#x4E00;&#x81F4;&#x3002;&#x53EF;&#x4EE5;&#x5728;&#x5DE5;&#x4F5C;&#x8282;&#x70B9;&#x4E0A;&#x4F7F;&#x7528; <code>docker ps -a | grep pause</code> &#x547D;&#x4EE4;&#x67E5;&#x770B; pause &#x5BB9;&#x5668;&#xFF1A;</p>
<p><img src="images/pod_pause.jpg" alt="pod_pause"></p>
<p>&#x4E0D;&#x8FC7;&#xFF0C;Docker &#x4E2D;&#x7684;&#x5BB9;&#x5668; IP &#x662F; 172.17.0.0 &#x5730;&#x5740;&#x6BB5;&#xFF0C;&#x800C; Pod IP &#x7684;&#x5730;&#x5740;&#x6BB5;&#x5374;&#x4E0D;&#x662F;&#x8FD9;&#x6837;&#x7684;&#xFF0C;&#x4E00;&#x822C;&#x662F; 10.x.x.x &#x7F51;&#x7EDC;&#xFF0C;&#x5176;&#x4E2D;&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49; Pod &#x662F; 10.32.0.0 &#x5730;&#x5740;&#x6BB5;&#x3002;</p>
<p><img src="images/pod_id.jpg" alt="pod_id"></p>
<p>&#x65E2;&#x7136; Pod &#x7684; IP &#x662F; Docker &#x5206;&#x914D;&#x7684;&#xFF0C;&#x4E3A;&#x4EC0;&#x4E48;&#x5176;&#x5730;&#x5740;&#x4E0D;&#x662F; 172.17.0.0 &#x5730;&#x5740;&#x6BB5;&#xFF1F;</p>
<p>&#x8FD8;&#x8BB0;&#x5F97;&#x6211;&#x4EEC;&#x5728;&#x90E8;&#x7F72; Kubernetes &#x96C6;&#x7FA4;&#x65F6;&#xFF0C;&#x90E8;&#x7F72;&#x7684; &#x7F51;&#x7EDC;&#x63D2;&#x4EF6;&#x5417;&#xFF1F;2.2 &#x7AE0;&#x4E2D;&#x4ECB;&#x7ECD;&#x7684; weave &#x7F51;&#x7EDC;&#x63D2;&#x4EF6;&#x3002;</p>
<p>&#x9996;&#x5148;&#xFF0C;&#x5728;&#x90E8;&#x7F72;&#x4E86; Docker &#x7684;&#x673A;&#x5668;&#x4E0A;&#xFF0C;&#x90FD;&#x4F1A;&#x6709;&#x4E00;&#x4E2A; docker0 &#x7684;&#x4E1C;&#x897F;&#xFF0C;&#x8FD9;&#x4E2A;&#x4E1C;&#x897F;&#x53EB;&#x7F51;&#x6865;&#x3002;</p>
<pre class="language-"><code class="lang-bash">root@slave1:~<span class="token comment"># ifconfig</span>
docker0: <span class="token assign-left variable">flags</span><span class="token operator">=</span><span class="token number">409</span><span class="token operator"><span class="token file-descriptor important">9</span>&lt;</span>UP,BROADCAST,MULTICAST<span class="token operator">&gt;</span>  mtu <span class="token number">1500</span>
        inet <span class="token number">172.17</span>.0.1  netmask <span class="token number">255.255</span>.0.0  broadcast <span class="token number">172.17</span>.255.255
        ether 02:42:fa:3e:f5:80  txqueuelen <span class="token number">0</span>  <span class="token punctuation">(</span>Ethernet<span class="token punctuation">)</span>
        RX packets <span class="token number">0</span>  bytes <span class="token number">0</span> <span class="token punctuation">(</span><span class="token number">0.0</span> B<span class="token punctuation">)</span>
        RX errors <span class="token number">0</span>  dropped <span class="token number">0</span>  overruns <span class="token number">0</span>  frame <span class="token number">0</span>
        TX packets <span class="token number">0</span>  bytes <span class="token number">0</span> <span class="token punctuation">(</span><span class="token number">0.0</span> B<span class="token punctuation">)</span>
        TX errors <span class="token number">0</span>  dropped <span class="token number">0</span> overruns <span class="token number">0</span>  carrier <span class="token number">0</span>  collisions <span class="token number">0</span>
</code></pre>
<p>docker &#x7684;&#x9ED8;&#x8BA4;&#x7F51;&#x6865;&#x53EB; docker0&#xFF0C;&#x8FD9;&#x4E2A;&#x7F51;&#x6865;&#x7684; IP &#x662F; 172.17.0.1&#xFF0C;&#x57FA;&#x4E8E;&#x8FD9;&#x4E2A;&#x7F51;&#x6865;&#x521B;&#x5EFA;&#x7684;&#x5BB9;&#x5668;&#x7684;&#x865A;&#x62DF;&#x7F51;&#x5361;&#x81EA;&#x7136;&#x662F; 172.17.0.0 &#x5730;&#x5740;&#x6BB5;&#x3002;</p>
<p>&#x800C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x4F7F;&#x7528; weava &#x7F51;&#x7EDC;&#x63D2;&#x4EF6;&#x90E8;&#x7F72;&#x96C6;&#x7FA4;&#xFF0C;&#x90A3;&#x4E48;&#x4F7F;&#x7528; ifconfig &#x547D;&#x4EE4;&#xFF0C;&#x53EF;&#x4EE5;&#x627E;&#x5230;&#x4E00;&#x4E2A; weava &#x7684;&#x81EA;&#x5B9A;&#x4E49;&#x7F51;&#x6865;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">weave: <span class="token assign-left variable">flags</span><span class="token operator">=</span><span class="token number">416</span><span class="token operator"><span class="token file-descriptor important">3</span>&lt;</span>UP,BROADCAST,RUNNING,MULTICAST<span class="token operator">&gt;</span>  mtu <span class="token number">1376</span>
        inet <span class="token number">10.32</span>.0.1  netmask <span class="token number">255.240</span>.0.0  broadcast <span class="token number">10.47</span>.255.255
        inet6 fe80::ac45:ebff:fe0a:31ae  prefixlen <span class="token number">64</span>  scopeid 0x2<span class="token operator"><span class="token file-descriptor important">0</span>&lt;</span>link<span class="token operator">&gt;</span>
        ether ae:45:eb:0a:31:ae  txqueuelen <span class="token number">1000</span>  <span class="token punctuation">(</span>Ethernet<span class="token punctuation">)</span>
        RX packets <span class="token number">2905588</span>  bytes <span class="token number">391313728</span> <span class="token punctuation">(</span><span class="token number">391.3</span> MB<span class="token punctuation">)</span>
        RX errors <span class="token number">0</span>  dropped <span class="token number">0</span>  overruns <span class="token number">0</span>  frame <span class="token number">0</span>
        TX packets <span class="token number">3179102</span>  bytes <span class="token number">640814125</span> <span class="token punctuation">(</span><span class="token number">640.8</span> MB<span class="token punctuation">)</span>
        TX errors <span class="token number">0</span>  dropped <span class="token number">0</span> overruns <span class="token number">0</span>  carrier <span class="token number">0</span>  collisions <span class="token number">0</span>
</code></pre>
<p>&#x770B;&#xFF0C;&#x8FD9;&#x4E0D;&#x5C31;&#x5BF9;&#x4E86;&#xFF0C;&#x901A;&#x8FC7; Kubernetes &#x521B;&#x5EFA;&#x7684;&#x81EA;&#x5B9A;&#x4E49; Pod&#xFF0C;&#x4F1A;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x7F51;&#x6865;&#x521B;&#x5EFA; IP&#xFF0C;&#x5176; IP &#x5730;&#x5740;&#x8DDF; &#x7F51;&#x7EDC;&#x63D2;&#x4EF6;&#x521B;&#x5EFA;&#x7684;&#x7F51;&#x6865;&#x6709;&#x5173;&#x3002;</p>
<blockquote>
<p><strong>[Info] &#x63D0;&#x793A;</strong></p>
<p>&#x8BFB;&#x8005;&#x5982;&#x679C;&#x60F3;&#x4E86;&#x89E3;&#x66F4;&#x591A;&#x7684; Docker &#x7F51;&#x7EDC;&#x77E5;&#x8BC6;&#xFF0C;&#x8BF7;&#x8BBF;&#x95EE; <a href="https://docs.docker.com/network/bridge/" target="_blank">https://docs.docker.com/network/bridge/</a></p>
</blockquote>
<h4 id="&#x8DE8;&#x8282;&#x70B9;&#x8BBF;&#x95EE;-pod"><a name="&#x8DE8;&#x8282;&#x70B9;&#x8BBF;&#x95EE;-pod" class="anchor-navigation-ex-anchor" href="#&#x8DE8;&#x8282;&#x70B9;&#x8BBF;&#x95EE;-pod"><i class="fa fa-link" aria-hidden="true"></i></a>&#x8DE8;&#x8282;&#x70B9;&#x8BBF;&#x95EE; Pod</h4>
<p>&#x65E2;&#x7136; Pod &#x7684; IP &#x662F; Docker &#x521B;&#x5EFA;&#x7684;&#xFF0C;&#x800C; Docker &#x521B;&#x5EFA;&#x7684; IP &#x53EA;&#x80FD;&#x5728;&#x672C;&#x5730;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x8BBF;&#x95EE;&#xFF0C;&#x90A3;&#x4E48;&#x600E;&#x4E48;&#x624D;&#x80FD;&#x5728;&#x522B;&#x7684;&#x8282;&#x70B9;&#x4E0A;&#x8BBF;&#x95EE;&#x8FD9;&#x4E2A; Pod IP&#xFF1F;&#x5F53;&#x7136;&#x662F;&#x7F51;&#x7EDC;&#x63D2;&#x4EF6;&#x5566;&#xFF0C;&#x5C31;&#x662F;&#x5728;&#x90E8;&#x7F72; Kubernetes &#x65F6;&#x4E00;&#x8D77;&#x90E8;&#x7F72;&#x7684; weave &#x3002;</p>
<p>&#x5F53;&#x7136;&#xFF0C;&#x9664;&#x4E86; weave &#xFF0C;&#x8FD8;&#x6709;&#x5F88;&#x591A;&#x7F51;&#x7EDC;&#x63D2;&#x4EF6;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#xFF0C;&#x5982;  calico&#x3001;flannel&#x3002;&#x56E0;&#x4E3A; Kubernetes &#x7F51;&#x7EDC;&#x6A21;&#x578B;&#x4E2D;&#x6709;&#x4E2A;&#x53EB; CNI &#x7684;&#x6807;&#x51C6;&#x63A5;&#x53E3;&#xFF0C;&#x53EA;&#x8981;&#x5B9E;&#x73B0;&#x4E86;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x7528;&#x5565;&#x7F51;&#x7EDC;&#x63D2;&#x4EF6;&#x90FD;&#x6CA1;&#x95EE;&#x9898;&#xFF0C;&#x4F7F;&#x7528;&#x8005;&#x4E0D;&#x9700;&#x8981;&#x5173;&#x5FC3;&#x63D2;&#x4EF6;&#x662F;&#x600E;&#x4E48;&#x5B9E;&#x73B0;&#x7684;&#x3002;</p>
<p>CNI &#x7684;&#x529F;&#x80FD;&#x5927;&#x6982;&#x662F;&#x4EE5;&#x4E0B;&#x51E0;&#x70B9;&#xFF1A;</p>
<ul>
<li>&#x8282;&#x70B9;&#x4E0A;&#x7684; Pod &#x53EF;&#x4EE5;&#x4E0D;&#x901A;&#x8FC7; NAT &#x548C;&#x5176;&#x4ED6;&#x4EFB;&#x4F55;&#x8282;&#x70B9;&#x4E0A;&#x7684; Pod &#x901A;&#x4FE1;(&#x79F0;&#x4E3A;&#x6241;&#x5E73;&#x5316;&#x7F51;&#x7EDC;)&#xFF0C;&#x5373;&#x8282;&#x70B9;&#x95F4; Pod &#x7684;&#x4E92;&#x76F8;&#x8BBF;&#x95EE;&#xFF1B;</li>
<li>&#x8282;&#x70B9;&#x4E0A;&#x7684;&#x4EE3;&#x7406;&#xFF08;&#x6BD4;&#x5982;&#xFF1A;&#x7CFB;&#x7EDF;&#x5B88;&#x62A4;&#x8FDB;&#x7A0B;&#x3001;kubelet&#xFF09;&#x53EF;&#x4EE5;&#x548C;&#x8282;&#x70B9;&#x4E0A;&#x7684;&#x6240;&#x6709; Pod &#x901A;&#x4FE1;&#xFF0C;&#x5373;&#x7CFB;&#x7EDF;&#x7EC4;&#x4EF6;&#x8BBF;&#x95EE; Pod&#xFF1B;</li>
</ul>
<h2 id="service"><a name="service" class="anchor-navigation-ex-anchor" href="#service"><i class="fa fa-link" aria-hidden="true"></i></a>Service</h2>
<p>Service &#x662F;&#x4E00;&#x79CD; Kubernetes &#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5B83;&#x8DDF;&#x7F51;&#x7EDC;&#x6709;&#x5173;&#xFF0C; Service &#x4E0D;&#x662F;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x8005;&#xFF0C;&#x4E5F;&#x4E0D;&#x662F;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x63A5;&#x53E3;&#x3002;</p>
<p>Service &#x662F;&#x5C06;&#x8FD0;&#x884C;&#x5728;&#x4E00;&#x7EC4; Pods &#x4E0A;&#x7684;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x516C;&#x5F00;&#x4E3A;&#x7F51;&#x7EDC;&#x670D;&#x52A1;&#x7684;&#x62BD;&#x8C61;&#x65B9;&#x6CD5;&#x3002;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x4F7F;&#x7528; Deployment &#x3001;Daemon &#x7B49;&#x90E8;&#x7F72; Pod&#xFF0C;&#x5219;&#x53EF;&#x4E3A;&#x6B64;&#x63A7;&#x5236;&#x5668;&#x521B;&#x5EFA; Service&#xFF0C;Service &#x4F1A;&#x76D1;&#x63A7;&#x6B64; Deployment &#x4E0A;&#x589E;&#x52A0;&#x6216;&#x79FB;&#x9664; Pod &#x7684;&#x64CD;&#x4F5C;&#xFF0C;&#x81EA;&#x52A8;&#x4E3A;&#x6240;&#x6709; Pod &#x63D0;&#x4F9B;&#x7F51;&#x7EDC;&#x670D;&#x52A1;&#x3002;&#x5F53;&#x7136;&#xFF0C;Service &#x5E76;&#x4E0D;&#x662F;&#x6307;&#x5411; Deployment&#x3001;Daemon &#x7684;&#xFF0C;&#x800C;&#x662F;&#x6307;&#x5411;&#x8FD9;&#x4E9B;&#x63A7;&#x5236;&#x5668;&#x4E0A;&#x7684; Pod&#xFF0C;&#x901A;&#x8FC7; Label &#x6307;&#x5411;&#x76F8;&#x5173;&#x7684; Pod&#x3002;</p>
<h3 id="&#x6CA1;&#x6709;-service-&#x65F6;"><a name="&#x6CA1;&#x6709;-service-&#x65F6;" class="anchor-navigation-ex-anchor" href="#&#x6CA1;&#x6709;-service-&#x65F6;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x6CA1;&#x6709; Service &#x65F6;</h3>
<p>&#x5047;&#x5982;&#x6709;&#x4E00;&#x7EC4; Web Pod&#xFF0C;&#x5982;&#x679C; Web &#x52A8;&#x6001;&#x4F38;&#x7F29;&#x526F;&#x672C;&#x6570;&#x91CF;&#x6216;&#x56E0;&#x4E3A;&#x67D0;&#x4E9B;&#x539F;&#x56E0; IP/&#x7AEF;&#x53E3;&#x53D1;&#x751F;&#x6539;&#x53D8;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5F88;&#x96BE;&#x8FFD;&#x8E2A;&#x8FD9;&#x79CD;&#x53D8;&#x5316;&#xFF0C;&#x6211;&#x4EEC;&#x5982;&#x4F55;&#x5728;&#x5BA2;&#x6237;&#x7AEF;&#x8BBF;&#x95EE;&#x8FD9;&#x7EC4; Web &#x670D;&#x52A1;&#xFF1F;&#x53C8;&#x5047;&#x5982; Web &#x670D;&#x52A1;&#x3001;Mysql &#x5206;&#x522B;&#x90E8;&#x7F72;&#x5728;&#x4E0D;&#x540C;&#x7684; Pod &#x4E2D;&#xFF0C;&#x90A3;&#x4E48; Web &#x5982;&#x4F55;&#x67E5;&#x627E;&#x5E76;&#x8DDF;&#x8E2A;&#x8981;&#x8FDE;&#x63A5;&#x7684; Mysql IP &#x5730;&#x5740;&#xFF1F;</p>
<p><img src="images/noservice.png" alt="noservice"></p>
<p>Service &#x53EF;&#x4EE5; &#x89E3;&#x51B3;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#x3002;Kubernetes Service &#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x79CD;&#x901A;&#x5E38;&#x79F0;&#x4E3A;&#x5FAE;&#x670D;&#x52A1;&#x7684;&#x62BD;&#x8C61;&#xFF0C;Service &#x4E3A;&#x903B;&#x8F91;&#x4E0A;&#x7684;&#x4E00;&#x7EC4; Pod &#x63D0;&#x4F9B;&#x53EF;&#x4EE5;&#x8BBF;&#x95EE;&#x5B83;&#x4EEC;&#x7684;&#x7B56;&#x7565; &#x3002;&#x5F53;&#x4F7F;&#x7528; Service &#x4E3A;&#x4E00;&#x7EC4; Pod &#x521B;&#x5EFA;&#x670D;&#x52A1;&#x65F6;&#xFF0C;&#x65E0;&#x8BBA;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E86;&#x591A;&#x5C11;&#x4E2A; Pod &#x526F;&#x672C;&#xFF0C;&#x8FD9;&#x4E9B; Pod &#x600E;&#x4E48;&#x53D8;&#x5316;&#xFF0C;Pod A &#x4E0D;&#x9700;&#x8981;&#x5173;&#x5FC3;&#x5B83;&#x4EEC;&#x8C03;&#x7528;&#x4E86;&#x54EA;&#x4E2A; Pod B &#x526F;&#x672C;&#xFF0C;&#x800C;&#x4E14;&#x4E0D;&#x9700;&#x8981;&#x77E5;&#x9053; Pod B &#x7684;&#x72B6;&#x6001;&#x4E5F;&#x4E0D;&#x9700;&#x8981;&#x8DDF;&#x8E2A; Pod B&#x3002;&#x56E0;&#x4E3A;Service &#x628A; Pod &#x7684;&#x8FD9;&#x79CD;&#x5173;&#x8054;&#x62BD;&#x8C61;&#x5316;&#xFF0C;&#x628A;&#x5B83;&#x4EEC;&#x89E3;&#x8026;&#x4E86;&#x3002;</p>
<h3 id="service-&#x7684;&#x5B9A;&#x4E49;&#x548C;&#x521B;&#x5EFA;"><a name="service-&#x7684;&#x5B9A;&#x4E49;&#x548C;&#x521B;&#x5EFA;" class="anchor-navigation-ex-anchor" href="#service-&#x7684;&#x5B9A;&#x4E49;&#x548C;&#x521B;&#x5EFA;"><i class="fa fa-link" aria-hidden="true"></i></a>Service &#x7684;&#x5B9A;&#x4E49;&#x548C;&#x521B;&#x5EFA;</h3>
<p>&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; Deployment &#x5BF9;&#x8C61;&#xFF0C;&#x5305;&#x542B;&#x4E09;&#x4E2A; Pod &#x5B9E;&#x4F8B;&#x3002;</p>
<pre class="language-"><code class="lang-bash">kubectl create deployment nginx --image<span class="token operator">=</span>nginx:latest --replicas<span class="token operator">=</span><span class="token number">3</span>
</code></pre>
<p>&#x63A5;&#x7740;&#xFF0C;&#x4E3A;&#x8FD9;&#x4E9B; Pod &#x521B;&#x5EFA;&#x4E00;&#x4E2A; Service&#x3002;</p>
<pre class="language-"><code>kubectl expose deployment nginx --type=ClusterIP --port=6666 --target-port=80
</code></pre><p>&#x67E5;&#x770B;&#x521B;&#x5EFA;&#x7684; Service&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">root@master:~<span class="token comment"># kubectl get service -o wide</span>
NAME           TYPE        CLUSTER-IP       EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>                               AGE     SELECTOR
kubernetes     ClusterIP   <span class="token number">10.96</span>.0.1        <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">443</span>/TCP                               3d12h   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>
mygoapp-dapr   ClusterIP   None             <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">80</span>/TCP,50001/TCP,50002/TCP,9090/TCP   17h     <span class="token assign-left variable">app</span><span class="token operator">=</span>mygoapp
nginx          ClusterIP   <span class="token number">10.107</span>.200.232   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">6666</span>/TCP
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;Service &#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x968F;&#x673A; IP  <code>10.107.200.232</code>&#xFF0C;&#x6211;&#x4EEC;&#x4E3A; Pod &#x6620;&#x5C04;&#x4E86;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x7AEF;&#x53E3;&#x4E3A; 6666&#xFF0C;&#x6B64;&#x7AEF;&#x53E3;&#x6620;&#x5C04;&#x5230;&#x4E86; Pod &#x7684; 80 &#x7AEF;&#x53E3;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6D4B;&#x8BD5;&#x8FD9;&#x4E2A; IP &#x548C; &#x7AEF;&#x53E3;&#x662F;&#x5426;&#x53EF;&#x7528;&#xFF1A;</p>
<pre class="language-"><code>curl 10.107.200.232:6666
</code></pre><blockquote>
<p>&#x5728;&#x90E8;&#x7F72;&#x4E86; Pod &#x7684;&#x673A;&#x5668;&#x4E0A;&#x624D;&#x80FD;&#x4F7F;&#x7528;&#x6B64; IP &#x548C;&#x7AEF;&#x53E3;&#x8BBF;&#x95EE; Pod&#x3002;</p>
</blockquote>
<p>&#x5047;&#x5982;&#x6709; master&#x3001;slave &#x4E24;&#x4E2A;&#x8282;&#x70B9;&#xFF0C;Pod &#x90FD;&#x88AB;&#x90E8;&#x7F72;&#x5230; slave &#x8282;&#x70B9;&#x4E0A;&#xFF0C;&#x800C; master &#x8282;&#x70B9;&#x6CA1;&#x6709;&#x90E8;&#x7F72;&#x6B64; Pod &#x7684;&#x8BDD;&#xFF0C;master &#x662F;&#x8BBF;&#x95EE;&#x4E0D;&#x4E86;&#x6B64; Service&#x7684;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x9A8C;&#x8BC1;&#x8FD9;&#x6837;&#x60C5;&#x51B5;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6D88;&#x53BB; master &#x7684;&#x6C61;&#x70B9;&#xFF0C;&#x4F7F;&#x5176;&#x80FD;&#x591F;&#x88AB;&#x90E8;&#x7F72;&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x7684; Pod&#x3002;</p>
<blockquote>
<p>&#x6B64;&#x65F6;&#x4F7F;&#x7528; DaemonSet &#x90E8;&#x7F72;&#x53EF;&#x80FD;&#x66F4;&#x52A0;&#x5408;&#x9002;&#x3002;</p>
</blockquote>
<pre class="language-"><code class="lang-bash">kubectl taint node instance-1 node-role.kubernetes.io/master:NoSchedule-
</code></pre>
<p>&#x7136;&#x540E;&#x91CD;&#x65B0;&#x90E8;&#x7F72; Deployment&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x90E8;&#x7F72; Service&#x3002;</p>
<pre class="language-"><code class="lang-bash">kubectl delete deployyment nginx
kubectl create deployment nginx --image<span class="token operator">=</span>nginx:latest --replicas<span class="token operator">=</span><span class="token number">3</span>
</code></pre>
<p>&#x67E5;&#x770B;&#x8FD9;&#x4E9B; Pod &#x90FD;&#x88AB;&#x90E8;&#x7F72;&#x5230;&#x54EA;&#x91CC;&#xFF1A;</p>
<pre class="language-"><code>root@master:~# kubectl get pods -o wide
NAME                       READY   STATUS           RESTARTS        AGE   IP           NODE     NOMINATED NODE   READINESS GATES
nginx-55649fd747-26f5q     1/1     Running            0             11s   10.44.0.3    master   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>none</span><span class="token punctuation">&gt;</span></span>           <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>none</span><span class="token punctuation">&gt;</span></span>
nginx-55649fd747-5znfc     1/1     Running            0             11s   10.44.0.4    master   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>none</span><span class="token punctuation">&gt;</span></span>           <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>none</span><span class="token punctuation">&gt;</span></span>
nginx-55649fd747-77k8m     1/1     Running            0             11s   10.32.0.3    slave1   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>none</span><span class="token punctuation">&gt;</span></span>           <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>none</span><span class="token punctuation">&gt;</span></span>
</code></pre><p>&#x770B;&#x6765; master&#x3001;slave &#x90FD;&#x90E8;&#x7F72;&#x4E86; Pod&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5728; master &#x8282;&#x70B9;&#x4E0A;&#x8BBF;&#x95EE;&#x6B64; Service&#xFF1A;</p>
<p><img src="images/service_master.jpg" alt="service_master"></p>
<p>&#x5728; Deployment &#x5BF9;&#x8C61;&#x4E0A;&#x521B;&#x5EFA; Service&#xFF0C;&#x4F1A;&#x76F4;&#x63A5;&#x5173;&#x8054;&#x4E00;&#x4E2A; Deployment &#x4E2D;&#x7684;&#x6240;&#x6709; Pod&#xFF0C;&#x5E76;&#x76D1;&#x63A7;&#x662F;&#x5426;&#x6709;&#x65B0;&#x5EFA;&#x6216;&#x79FB;&#x9664; Pod &#xFF0C;&#x8FD9;&#x6837;&#x65E0;&#x8BBA; Pod &#x7684;&#x6570;&#x91CF;&#x6709;&#x591A;&#x5C11;&#xFF0C;Service &#x90FD;&#x53EF;&#x4EE5;&#x4EE3;&#x7406;&#x8FD9;&#x4E9B; Pod&#x3002;</p>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x901A;&#x8FC7; YAML &#x5B9A;&#x4E49; Service&#xFF0C;&#x5176;&#x6A21;&#x677F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml"><span class="token key atrule">apiVersion</span><span class="token punctuation">:</span> v1
<span class="token key atrule">kind</span><span class="token punctuation">:</span> Service
<span class="token key atrule">metadata</span><span class="token punctuation">:</span>
  <span class="token key atrule">name</span><span class="token punctuation">:</span> my<span class="token punctuation">-</span>service
<span class="token key atrule">spec</span><span class="token punctuation">:</span>
  <span class="token key atrule">selector</span><span class="token punctuation">:</span>
    <span class="token key atrule">app</span><span class="token punctuation">:</span> MyApp
  <span class="token key atrule">ports</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">protocol</span><span class="token punctuation">:</span> TCP
      <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">6666</span>
      <span class="token key atrule">targetPort</span><span class="token punctuation">:</span> <span class="token number">80</span>
  <span class="token key atrule">type</span><span class="token punctuation">:</span> ClusterIP
</code></pre>
<blockquote>
<p><strong>[Error] &#x63D0;&#x793A;</strong></p>
<p>&#x7531;&#x4E8E; Service &#x7684; IP &#x662F;&#x865A;&#x62DF;&#x7684;&#xFF0C;&#x56E0;&#x6B64;&#x6B64; IP &#x662F;&#x65E0;&#x6CD5; Ping &#x901A;&#x7684;&#x3002;</p>
</blockquote>
<h3 id="service-&#x5916;&#x90E8;&#x670D;&#x52A1;&#x7C7B;&#x578B;"><a name="service-&#x5916;&#x90E8;&#x670D;&#x52A1;&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#service-&#x5916;&#x90E8;&#x670D;&#x52A1;&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>Service &#x5916;&#x90E8;&#x670D;&#x52A1;&#x7C7B;&#x578B;</h3>
<p>&#x867D;&#x7136;&#x521B;&#x5EFA;&#x4E86; Service &#x540E;&#xFF0C;&#x6240;&#x6709;&#x7684; Pod &#x53EF;&#x4EE5;&#x88AB;&#x4E00;&#x4E2A; IP &#x5730;&#x5740;&#x8BBF;&#x95EE;&#xFF0C;&#x4F46;&#x662F;&#x8FD9;&#x4E2A; IP &#x53EA;&#x80FD;&#x5728;&#x88AB;&#x90E8;&#x7F72;&#x4E86; Pod &#x7684;&#x8282;&#x70B9;&#x4E2D;&#x8BBF;&#x95EE;&#xFF0C;&#x5E76;&#x4E14;&#x8FD9;&#x4E2A; IP &#x4E0D;&#x80FD;&#x88AB;&#x96C6;&#x7FA4;&#x5916;&#x8BBF;&#x95EE;&#xFF0C;&#x8FD9;&#x662F;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x521B;&#x5EFA; Service &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F7F;&#x7528;&#x4E86; ClusterIP &#x7C7B;&#x578B;&#xFF0C;&#x5982;&#x679C;&#x662F; NodePort &#x7C7B;&#x578B;&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x88AB;&#x5916;&#x754C;&#x8BBF;&#x95EE;&#x5230;&#x3002;</p>
<p>Kubernetes Service &#x6709;&#x4E2A; ServiceType &#xFF0C;&#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x6307;&#x5B9A;&#x5982;&#x4F55;&#x66B4;&#x9732;&#x670D;&#x52A1;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x4E00;&#x4E2A; Service &#x66B4;&#x9732;&#x5230;&#x96C6;&#x7FA4;&#x5916;&#x90E8;&#xFF0C;&#x5916;&#x754C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; IP &#x8BBF;&#x95EE;&#x8FD9;&#x4E2A; Service&#x3002;</p>
<p>Type &#x6709;&#x56DB;&#x79CD;&#x7C7B;&#x578B;&#xFF0C;&#x5176;&#x53D6;&#x503C;&#x8BF4;&#x660E;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li><p>ClusterIP</p>
<p>&#x901A;&#x8FC7;&#x96C6;&#x7FA4;&#x5185;&#x90E8; IP &#x66B4;&#x9732;&#x670D;&#x52A1;&#xFF0C;ClusterIP &#x662F; ServiceType &#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x3002;</p>
</li>
<li><p>NodePort</p>
<p>&#x901A;&#x8FC7;&#x6BCF;&#x4E2A;&#x8282;&#x70B9;&#x4E0A;&#x7684; IP &#x548C;&#x9759;&#x6001;&#x7AEF;&#x53E3;&#xFF08;<code>NodePort</code>&#xFF09;&#x66B4;&#x9732;&#x670D;&#x52A1;&#x3002;&#x7531;&#x4E8E;&#x5176;&#x662F;&#x8282;&#x70B9;&#x4E0A;&#x7684; &#xFF0C;&#x6240;&#x4EE5;&#x5177;&#x6709;&#x901A;&#x8FC7;&#x8282;&#x70B9;&#x7684;&#x516C;&#x7F51; IP &#x8BBF;&#x95EE;&#x8FD9;&#x4E2A;&#x670D;&#x52A1;&#x3002;</p>
</li>
<li><p>LoadBalancer</p>
<p>&#x4F7F;&#x7528;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#x5411;&#x5916;&#x90E8;&#x66B4;&#x9732;&#x670D;&#x52A1;&#x3002; &#x5916;&#x90E8;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#x53EF;&#x4EE5;&#x5C06;&#x6D41;&#x91CF;&#x8DEF;&#x7531;&#x5230;&#x81EA;&#x52A8;&#x521B;&#x5EFA;&#x7684; <code>NodePort</code> &#x670D;&#x52A1;&#x548C; <code>ClusterIP</code> &#x670D;&#x52A1;&#x4E0A;&#x3002;&#x9700;&#x8981;&#x4E91;&#x5E73;&#x53F0;&#x670D;&#x52A1;&#x63D0;&#x4F9B;&#x5546;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x5206;&#x914D;&#x516C;&#x7F51; IP &#x624D;&#x80FD;&#x4F7F;&#x7528;&#x3002;</p>
</li>
<li><p><code>ExternalName</code></p>
<p>&#x901A;&#x8FC7;&#x8FD4;&#x56DE; <code>CNAME</code> &#x548C;&#x5BF9;&#x5E94;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x670D;&#x52A1;&#x6620;&#x5C04;&#x5230; <code>externalName</code> &#x5B57;&#x6BB5;&#x7684;&#x5185;&#x5BB9;&#xFF08;&#x4F8B;&#x5982;&#xFF0C;<code>foo.bar.example.com</code>&#xFF09;&#x3002;</p>
<blockquote>
<p>&#x9700;&#x8981;&#x4F7F;&#x7528; kube-dns 1.7 &#x53CA;&#x4EE5;&#x4E0A;&#x7248;&#x672C;&#x6216;&#x8005; CoreDNS 0.0.8 &#x53CA;&#x4EE5;&#x4E0A;&#x7248;&#x672C;&#x624D;&#x80FD;&#x4F7F;&#x7528; <code>ExternalName</code> &#x7C7B;&#x578B;&#x3002;</p>
</blockquote>
</li>
</ul>
<p>ClusterIP&#x3001;NodePort&#x3001;LoadBalancer &#x4E09;&#x8005;&#x662F;&#x6709;&#x5173;&#x7CFB;&#x7684;&#xFF0C;&#x524D;&#x8005;&#x662F;&#x540E;&#x8005;&#x7684;&#x57FA;&#x7840;&#x3002;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; NodePort &#x7C7B;&#x578B;&#x7684; Service&#xFF0C;&#x5FC5;&#x5B9A;&#x5E26;&#x6709;&#x4E00;&#x4E2A; ClusterIP&#xFF1B;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; LoadBalancer&#xFF0C;&#x5FC5;&#x5B9A;&#x5E26;&#x6709; ClusterIP&#x3001;NodePort&#x3002;</p>
<h3 id="&#x914D;&#x7F6E;-servicetype-&#x516C;&#x5F00;-service"><a name="&#x914D;&#x7F6E;-servicetype-&#x516C;&#x5F00;-service" class="anchor-navigation-ex-anchor" href="#&#x914D;&#x7F6E;-servicetype-&#x516C;&#x5F00;-service"><i class="fa fa-link" aria-hidden="true"></i></a>&#x914D;&#x7F6E; ServiceType &#x516C;&#x5F00; Service</h3>
<p>&#x6211;&#x4EEC;&#x4F7F;&#x7528; <code>kubectl edit service nginx</code> &#x5C06;&#x524D;&#x9762;&#x521B;&#x5EFA;&#x7684; Service &#x4FEE;&#x6539;&#x4E3A; NodePort &#x7C7B;&#x578B;&#xFF0C;&#x7136;&#x540E;&#x67E5;&#x770B; Service &#x5217;&#x8868;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">root@master:~<span class="token comment"># kubectl get services -o wide</span>
NAME           TYPE        CLUSTER-IP       EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>                               AGE     SELECTOR
kubernetes     ClusterIP   <span class="token number">10.96</span>.0.1        <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">443</span>/TCP                               3d13h   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>
nginx          NodePort    <span class="token number">10.107</span>.200.232   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>        <span class="token number">6666</span>:30291/TCP                        27m     <span class="token assign-left variable">app</span><span class="token operator">=</span>nginx
</code></pre>
<p>&#x6B64;&#x65F6; Service &#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; &#x968F;&#x673A;&#x7AEF;&#x53E3;&#xFF0C;&#x8FD9;&#x4E2A;&#x7AEF;&#x53E3;&#x6620;&#x5C04;&#x5230;&#x6BCF;&#x4E2A;&#x90E8;&#x7F72;&#x4E86;  Pod &#x7684;&#x8282;&#x70B9;&#x4E0A;&#xFF0C;&#x4F8B;&#x5982;&#x7B14;&#x8005;&#x7684;&#x662F; 30291&#xFF0C;&#x6B64;&#x65F6;&#x5916;&#x754C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4F7F;&#x7528;&#x8282;&#x70B9; IP &#x8BBF;&#x95EE;&#x6B64; Service&#x3002;</p>
<p>&#x6BCF;&#x4E2A;&#x8282;&#x70B9;&#x4E0A;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; 127.0.0.1:30291 &#x8BBF;&#x95EE;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x516C;&#x7F51; IP &#x8BBF;&#x95EE;&#x3002;</p>
<p><img src="images/visit_service.jpg" alt="visit_service"></p>
<p>&#x7528;&#x6237;&#x53D1;&#x8D77;&#x8BF7;&#x6C42;&#x540E;&#xFF0C;&#x8BF7;&#x6C42;&#x8F6C;&#x53D1;&#x81F3; Pod &#x7684;&#x8FC7;&#x7A0B;&#x5982;&#x4E0B;&#xFF1A; </p>
<div class="mermaid">
graph TD;
    &#x7528;&#x6237; ==&gt; Host(&#x516C;&#x7F51;IP:30291)
    Host == NodePort ==&gt; Service(Service:6666)
    Service == ClusterIP ==&gt; Pod1(Pod1:80);
    Service == ClusterIP ==&gt; Pod2(Pod2:80);
    Service == ClusterIP ==&gt; Pod3(Pod3:80);
</div>



<h3 id="loadbalancer"><a name="loadbalancer" class="anchor-navigation-ex-anchor" href="#loadbalancer"><i class="fa fa-link" aria-hidden="true"></i></a>LoadBalancer</h3>
<p>&#x5F53;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x516C;&#x7F51; IP  &#x8BBF;&#x95EE; Pod &#x65F6;&#xFF0C;&#x4E5F;&#x51FA;&#x73B0;&#x4E86;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;Pod &#x662F;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x4E86;&#xFF0C;&#x4F46;&#x662F;&#x603B;&#x4E0D;&#x80FD;&#x53EA;&#x8BBF;&#x95EE;&#x4E00;&#x4E2A;&#x8282;&#x70B9;&#x5427;&#xFF1F;&#x8282;&#x70B9;&#x7684;&#x7F51;&#x7EDC;&#x4E5F;&#x9700;&#x8981;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5440;&#xFF0C;&#x800C;&#x4E14;&#x8282;&#x70B9; IP &#x8FD9;&#x4E48;&#x591A;&#xFF0C;&#x7528;&#x6237;&#x603B;&#x4E0D;&#x80FD;&#x8BB0;&#x4F4F;&#x8FD9;&#x4E48;&#x591A; IP &#x5427;&#xFF1F;&#x5C31;&#x7B97;&#x4F7F;&#x7528;&#x57DF;&#x540D;&#xFF0C;&#x57DF;&#x540D;&#x4E5F;&#x4E0D;&#x80FD;&#x7ED1;&#x5B9A;&#x8FD9;&#x4E48;&#x591A; IP &#x5440;&#xFF0C;&#x6B64;&#x65F6; LoadBalancer &#x53EF;&#x4EE5;&#x5E2E;&#x5230;&#x4F60;&#x3002;</p>
<p>&#x5F53;&#x4F7F;&#x7528; LoadBalancer &#x66B4;&#x9732;&#x670D;&#x52A1;&#x5230;&#x96C6;&#x7FA4;&#x5916;&#x90E8;&#x7F51;&#x7EDC;&#x65F6;&#xFF0C;&#x4E91;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x9700;&#x8981;&#x65F6;&#x95F4;&#x6765;&#x521B;&#x5EFA;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#x5E76;&#x83B7;&#x53D6;&#x670D;&#x52A1;&#x4E2D;&#x7684; IP &#x5730;&#x5740;&#x3002;&#x5982;&#x679C;&#x4F7F;&#x7528;&#x7684;&#x662F; <code>minikube</code>&#x3001;<code>kubeadm</code> &#x7B49;&#x521B;&#x5EFA;&#x7684;&#x81EA;&#x5B9A;&#x4E49; Kubernetes &#x96C6;&#x7FA4;&#xFF0C;&#x6CA1;&#x6709;&#x96C6;&#x6210; LoadBalancer &#xFF0C;&#x5219;&#x4F1A;&#x4E00;&#x76F4;&#x5904;&#x4E8E; <code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Pending</span><span class="token punctuation">&gt;</span></span></code> &#x72B6;&#x6001;&#x3002;</p>
<div class="mermaid">
graph TD;
    &#x7528;&#x6237; ==&gt; LoadBalancer(123.123.123.123)
    LoadBalancer ==&gt; Host1(100.100.100.1)
    LoadBalancer ==&gt; Host2(100.100.100.2)
    LoadBalancer ==&gt; Host3(100.100.100.3)
    LoadBalancer ==&gt; Host4(100.100.100.4)
</div>





<p>&#x6211;&#x4EEC;&#x5220;&#x9664;&#x4E4B;&#x524D; Deployment &#x90E8;&#x7F72; nginx &#x65F6;&#xFF0C;&#x901A;&#x8FC7; expose &#x521B;&#x5EFA;&#x7684; Service&#x3002;</p>
<pre class="language-"><code class="lang-bash">kubectl delete <span class="token function">service</span> nginx
</code></pre>
<p>&#x7136;&#x540E;&#x91CD;&#x65B0;&#x521B;&#x5EFA; service&#x3002;</p>
<pre class="language-"><code class="lang-bash">kubectl expose deployment nginx --type<span class="token operator">=</span>LoadBalancer --port<span class="token operator">=</span><span class="token number">80</span> --target-port<span class="token operator">=</span><span class="token number">6666</span>
<span class="token comment"># &#x53EF;&#x4EE5;&#x53EA;&#x586B;&#x5199; --port &#xFF0C;&#x6B64;&#x65F6;&#x6620;&#x5C04;&#x7684;&#x7AEF;&#x53E3;&#x8DDF; Pod &#x7AEF;&#x53E3;&#x4E00;&#x81F4;</span>
</code></pre>
<p>&#x67E5;&#x8BE2; Service&#xFF1A;</p>
<pre class="language-"><code>NAME         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>none</span><span class="token punctuation">&gt;</span></span>        443/TCP        29h
nginx        LoadBalancer   10.97.249.37   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>pending</span><span class="token punctuation">&gt;</span></span>     80:31036/TCP   30s
</code></pre><pre class="language-"><code class="lang-yaml">  <span class="token key atrule">ports</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">nodePort</span><span class="token punctuation">:</span> <span class="token number">31036</span>
    <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">6666</span>
    <span class="token key atrule">protocol</span><span class="token punctuation">:</span> TCP
    <span class="token key atrule">targetPort</span><span class="token punctuation">:</span> <span class="token number">80</span>
  <span class="token key atrule">sessionAffinity</span><span class="token punctuation">:</span> None
</code></pre>
<p>LoadBalancer &#x9700;&#x8981;&#x4E91;&#x670D;&#x52A1;&#x5546;&#x652F;&#x6301;&#xFF0C;&#x800C;&#x4E14;&#x6536;&#x8D39;&#xFF0C;&#x8FD9;&#x91CC;&#x5C31;&#x4E0D;&#x505A;&#x5176;&#x4ED6;&#x5B9E;&#x9A8C;&#x4E86;&#xFF0C;&#x8BFB;&#x8005;&#x77E5;&#x9053;&#x5C31;&#x884C;&#x3002;</p>
<p><img src="images/service.png" alt=""></p>
<p>&#x524D;&#x9762;&#x63D0;&#x5230;&#x7684; LoadBalancer &#x4FBF;&#x662F;&#x8D1F;&#x8F7D;&#x5747;&#x8861;&#x5668;&#xFF0C;&#x5728; Kubernetes &#x4E0A;&#x521B;&#x5EFA; LoadBalancer &#x9700;&#x8981;&#x4E91;&#x5E73;&#x53F0;&#x7684;&#x652F;&#x6301;&#xFF0C;&#x8BFB;&#x8005;&#x53EF;&#x53C2;&#x8003;&#x817E;&#x8BAF;&#x4E91;&#x7684; CLB&#x3002;</p>
<h3 id="service-&#x5982;&#x4F55;&#x9009;&#x62E9;-pod"><a name="service-&#x5982;&#x4F55;&#x9009;&#x62E9;-pod" class="anchor-navigation-ex-anchor" href="#service-&#x5982;&#x4F55;&#x9009;&#x62E9;-pod"><i class="fa fa-link" aria-hidden="true"></i></a>Service &#x5982;&#x4F55;&#x9009;&#x62E9; Pod</h3>
<p>&#x5F53;&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x5916;&#x90E8;&#x7F51;&#x7EDC;&#x8BBF;&#x95EE;&#x65F6;&#xFF0C;Service &#x4F1A;&#x81EA;&#x52A8;&#x63D0;&#x4F9B;&#x5176;&#x4E2D;&#x4E00;&#x4E2A; Pod &#x7ED9;&#x6211;&#x4EEC;&#x3002;</p>
<pre class="language-"><code>               ------------
               |         |
--- &#x8BBF;&#x95EE;  --&gt;   |   pod1  |
               |   pod2  |
               |   pod3  |
               ------------
</code></pre><p>&#x6211;&#x4EEC;&#x67E5;&#x770B;&#x4E0A;&#x4E00;&#x4E2A;&#x5C0F;&#x8282;&#x521B;&#x5EFA;&#x7684; Service &#x7684; YAML &#x6587;&#x4EF6;&#xFF1A;</p>
<pre class="language-"><code class="lang-yaml">  <span class="token key atrule">clusterIP</span><span class="token punctuation">:</span> 10.100.66.200
  <span class="token key atrule">clusterIPs</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> 10.100.66.200
<span class="token punctuation">...</span> <span class="token punctuation">...</span>
  <span class="token key atrule">ports</span><span class="token punctuation">:</span>
  <span class="token punctuation">-</span> <span class="token key atrule">nodePort</span><span class="token punctuation">:</span> <span class="token number">31672</span>
    <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">6666</span>
    <span class="token key atrule">protocol</span><span class="token punctuation">:</span> TCP
    <span class="token key atrule">targetPort</span><span class="token punctuation">:</span> <span class="token number">80</span>
</code></pre>
<p>&#x6B64; Service &#x7684; IP &#x662F; 10.100.66.200&#xFF0C;&#x5176;&#x7C7B;&#x578B;&#x662F; ClusterIP&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x96C6;&#x7FA4;&#x5185;&#x90E8;&#x6240;&#x6709;&#x8282;&#x70B9;&#x4E0A;&#x8BBF;&#x95EE;&#xFF0C;&#x5982;&#x679C;&#x96C6;&#x7FA4;&#x6CA1;&#x6709;&#x5B89;&#x88C5;&#x7F51;&#x7EDC;&#x63D2;&#x4EF6;&#xFF0C;&#x5219; master &#x8282;&#x70B9;&#x4E0A;&#x662F;&#x6CA1;&#x6CD5;&#x8BBF;&#x95EE;&#x7684;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x7684;&#x662F; <code>NodePort</code> &#x7F51;&#x7EDC;&#x7C7B;&#x578B;&#xFF0C;&#x6240;&#x4EE5;&#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A; node &#x7AEF;&#x53E3;&#xFF0C;&#x6B64;&#x7AEF;&#x53E3;&#x4F1A;&#x6620;&#x5C04;&#x5230;&#x8282;&#x70B9;&#x672C;&#x5730;&#x7F51;&#x7EDC;&#x4E0A;&#x3002;&#x4F8B;&#x5982;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4EFB;&#x610F;&#x80FD;&#x591F;&#x8FDE;&#x63A5;&#x6B64;&#x8282;&#x70B9;&#x7684; IP &#x8FDB;&#x884C;&#x8BBF;&#x95EE;&#xFF0C;&#x4F8B;&#x5982; <code>127.0.0.1:31672</code>&#xFF0C;&#x6216;&#x8005;&#x8BBF;&#x95EE;&#x6B64;&#x8282;&#x70B9;&#x7684;&#x5185;&#x7F51; IP&#x3001;&#x516C;&#x7F51; IP &#x3002;</p>
<p>&#x73B0;&#x5728;&#x77E5;&#x9053;&#x5916;&#x754C;&#x600E;&#x4E48;&#x8BBF;&#x95EE;&#x6B64; Service&#xFF0C;&#x6211;&#x4EEC;&#x518D;&#x6765;&#x770B;&#x770B;&#xFF0C;Service &#x600E;&#x4E48;&#x9009;&#x62E9;&#x54EA;&#x4E2A; Pod &#x63D0;&#x4F9B;&#x670D;&#x52A1;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x67E5;&#x770B;&#x901A;&#x8FC7; Deployment &#x521B;&#x5EFA;&#x7684; pod&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">kubectl get pods -o wide
</code></pre>
<pre class="language-"><code class="lang-bash">NAME                        IP              NODE       NOMINATED NODE   READINESS GATES
nginx-55649fd747-9fzlr    <span class="token number">192.168</span>.56.56    instance-2   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>           <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>
nginx-55649fd747-ckhrw    <span class="token number">192.168</span>.56.57    instance-2   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>           <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>
nginx-55649fd747-ldzkf    <span class="token number">192.168</span>.23.58    instance-2   <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>           <span class="token operator">&lt;</span>none<span class="token operator">&gt;</span>
</code></pre>
<p>&#x7136;&#x540E;&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x547D;&#x4EE4;&#x67E5;&#x770B; iptables &#x914D;&#x7F6E;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash">iptables-save
</code></pre>
<p>&#x5728;&#x7EC8;&#x7AEF;&#x63A7;&#x5236;&#x53F0;&#x4E2D;&#x67E5;&#x627E; <code>random</code> &#x5173;&#x952E;&#x5B57;&#xFF1A;</p>
<p><img src="images/service_iptables.png" alt="service_iptables"></p>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x6709;&#x4E09;&#x4E2A; <code>default/nginx</code>&#xFF0C; &#x7B2C;&#x4E00;&#x4E2A; pod &#x88AB;&#x8BBF;&#x95EE;&#x7684;&#x673A;&#x4F1A;&#x662F; <code>0.33333...</code>&#x3002;&#x5728;&#x5269;&#x4E0B;&#x7684; 2/3 &#x7684;&#x6982;&#x7387;&#x4E2D;&#xFF0C;&#x6709; 0.5 &#x7684;&#x6982;&#x7387;&#x9009;&#x62E9;&#x7B2C;&#x4E8C;&#x4E2A; Pod&#xFF0C;&#x5269;&#x4E0B;&#x7684; 1/3 &#x6982;&#x7387;&#x9009;&#x62E9;&#x7B2C;&#x4E09;&#x4E2A; Pod&#x3002;&#x8FD9;&#x79CD;&#x968F;&#x673A;&#x9009;&#x62E9;&#x7684;&#x6A21;&#x5F0F;&#x79F0;&#x4E3A; iptables &#x4EE3;&#x7406;&#x6A21;&#x5F0F;&#x3002;</p>
<h3 id="kube-proxy-&#x4E09;&#x79CD;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;"><a name="kube-proxy-&#x4E09;&#x79CD;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#kube-proxy-&#x4E09;&#x79CD;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>kube-proxy &#x4E09;&#x79CD;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;</h3>
<p>&#x672C;&#x8282;&#x5185;&#x5BB9;&#x4E86;&#x89E3;&#x7B80;&#x5355;&#x4E86;&#x89E3;&#x5373;&#x53EF;&#x3002;</p>
<p>&#x5F53;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x547D;&#x4EE4;&#x521B;&#x5EFA;&#x4E00;&#x4E2A; Service &#x65F6;&#xFF0C;&#x53EF;&#x770B;&#x5230;&#x6BCF;&#x4E2A; Service &#x90FD;&#x6709;&#x4E00;&#x4E2A; IP &#x5730;&#x5740;&#xFF0C;&#x8FD9;&#x662F;&#x7531; kube-proxy &#x8D1F;&#x8D23;&#x4E3A; Service &#x5B9E;&#x73B0;&#x7684;&#x4E00;&#x79CD;&#x865A;&#x62DF; IP &#xFF0C;&#x5373; <code>ClusterIP</code>&#x3002;</p>
<p>kube-proxy &#x53EF;&#x4EE5;&#x4E3A;&#x591A;&#x4E2A; Pod &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x7EDF;&#x4E00;&#x7684;&#x4EE3;&#x7406;&#xFF0C;&#x5728;&#x8BBF;&#x95EE; Service &#x65F6;&#xFF0C;&#x81EA;&#x52A8;&#x9009;&#x62E9;&#x4E00;&#x4E2A; Pod &#x63D0;&#x4F9B;&#x670D;&#x52A1;&#xFF0C;&#x81F3;&#x4E8E;&#x5982;&#x4F55;&#x9009;&#x62E9; Pod&#xFF0C;kube-proxy &#x6709;&#x4E09;&#x79CD;&#x6A21;&#x5F0F;&#x3002;</p>
<ul>
<li>userspace &#x4EE3;&#x7406;&#x6A21;&#x5F0F;</li>
<li>iptables &#x4EE3;&#x7406;&#x6A21;&#x5F0F;(&#x9ED8;&#x8BA4;)</li>
<li>IPVS &#x4EE3;&#x7406;&#x6A21;&#x5F0F;&#xFF08;Kubernetes v1.11 [stable]&#xFF0C;&#x5982;&#x679C;&#x8981;&#x4F7F;&#x7528; IPVS&#xFF0C;&#x9700;&#x8981;&#x4FEE;&#x6539;&#x914D;&#x7F6E;&#x6FC0;&#x6D3B;&#xFF09;</li>
</ul>
<p>&#x5728;&#x8FD9;&#x4E9B;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x53EF;&#x4EE5;&#x5728;&#x4E0D;&#x4E86;&#x89E3; Kubernetes &#x670D;&#x52A1;&#x6216; Pod &#x7684;&#x4EFB;&#x4F55;&#x4FE1;&#x606F;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5C06; Port &#x4EE3;&#x7406;&#x5230;&#x9002;&#x5F53;&#x7684;&#x540E;&#x7AEF;&#x3002;</p>
<p><img src="images/s1.png" alt="s1"></p>
<h4 id="userspace-&#x6A21;&#x5F0F;"><a name="userspace-&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#userspace-&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>userspace &#x6A21;&#x5F0F;</h4>
<p>userspace &#x6A21;&#x5F0F;&#x4E0B;&#xFF0C; kube-proxy &#x901A;&#x8FC7;&#x8F6E;&#x8F6C;&#x7B97;&#x6CD5;&#x9009;&#x62E9;&#x540E;&#x7AEF;&#x3002;</p>
<p>&#x5BF9;&#x6BCF;&#x4E2A; Service&#xFF0C;&#x5B83;&#x4F1A;&#x5728;&#x672C;&#x5730; Node &#x4E0A;&#x6253;&#x5F00;&#x4E00;&#x4E2A;&#x7AEF;&#x53E3;(&#x7AEF;&#x53E3;&#x53F7;&#x5927;&#x4E8E; 30000)&#x3002; &#x4EFB;&#x4F55;&#x8FDE;&#x63A5;&#x5230;&#x6B64;&#x7AEF;&#x53E3;&#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x90FD;&#x4F1A;&#x88AB;&#x4EE3;&#x7406;&#x5230; Service &#x540E;&#x7AEF;&#x7684;&#x67D0;&#x4E2A; <code>Pod</code> &#x4E0A;&#x3002; &#x4F7F;&#x7528;&#x54EA;&#x4E2A;&#x540E;&#x7AEF; Pod&#xFF0C;&#x662F; kube-proxy &#x57FA;&#x4E8E; YAML &#x7684; <code>SessionAffinity</code> &#x7EC8;&#x7AEF;&#x6765;&#x786E;&#x5B9A;&#x7684;&#x3002;</p>
<p>&#x6700;&#x540E;&#xFF0C;&#x5B83;&#x914D;&#x7F6E; iptables &#x89C4;&#x5219;&#xFF0C;&#x6355;&#x83B7;&#x5230;&#x8FBE;&#x8BE5; Service &#x7684; <code>clusterIP</code> &#x548C; <code>Port</code> &#x7684;&#x8BF7;&#x6C42;&#xFF0C;&#x5E76;&#x91CD;&#x5B9A;&#x5411;&#x5230;&#x4EE3;&#x7406;&#x7AEF;&#x53E3;&#xFF0C;&#x4EE3;&#x7406;&#x7AEF;&#x53E3;&#x518D;&#x4EE3;&#x7406;&#x8BF7;&#x6C42;&#x5230;&#x540E;&#x7AEF; Pod&#x3002;</p>
<pre class="language-"><code>&#x8BBF;&#x95EE; -&gt; clusterIP -&gt; &#x4EE3;&#x7406; -&gt; &#x4EFB;&#x4E00; Pod
</code></pre><p><img src="images/s2.png" alt="s2"></p>
<h4 id="iptables-&#x4EE3;&#x7406;&#x6A21;&#x5F0F;"><a name="iptables-&#x4EE3;&#x7406;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#iptables-&#x4EE3;&#x7406;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>iptables &#x4EE3;&#x7406;&#x6A21;&#x5F0F;</h4>
<p>kube-proxy &#x9ED8;&#x8BA4;&#x6A21;&#x5F0F;&#x3002;iptables &#x4EE3;&#x7406;&#x6A21;&#x5F0F;&#x7684;&#x7B56;&#x7565;&#x662F;&#xFF0C;kube-proxy &#x5728; iptables &#x6A21;&#x5F0F;&#x4E0B;<strong>&#x968F;&#x673A;&#x9009;&#x62E9;&#x4E00;&#x4E2A; Pod</strong>&#x3002;</p>
<p>&#x5B83;&#x4F1A;&#x4E3A;&#x6BCF;&#x4E2A; Service &#x914D;&#x7F6E; iptables &#x89C4;&#x5219;&#xFF0C;&#x6355;&#x83B7;&#x6240;&#x6709;&#x8BBF;&#x95EE;&#x6B64; Service &#x7684; <code>clusterIP</code>&#x8BF7;&#x6C42;&#xFF0C;&#x8FDB;&#x800C;&#x5C06;&#x8BF7;&#x6C42;&#x91CD;&#x5B9A;&#x5411;&#x5230; Service &#x7684;&#x4E00;&#x7EC4;&#x540E;&#x7AEF;&#x4E2D;&#x7684;&#x67D0;&#x4E2A; Pod &#x4E0A;&#x9762;&#x3002; &#x5BF9;&#x4E8E;&#x6BCF;&#x4E2A; Endpoints &#x5BF9;&#x8C61;&#xFF0C;&#x5B83;&#x4E5F;&#x4F1A;&#x914D;&#x7F6E; iptables &#x89C4;&#x5219;&#xFF0C;&#x8FD9;&#x4E2A;&#x89C4;&#x5219;&#x4F1A;&#x9009;&#x62E9;&#x4E00;&#x4E2A;&#x540E;&#x7AEF;&#x7EC4;&#x5408;&#x3002;</p>
<p>&#x4F7F;&#x7528; iptables &#x5904;&#x7406;&#x6D41;&#x91CF;&#x5177;&#x6709;&#x8F83;&#x4F4E;&#x7684;&#x7CFB;&#x7EDF;&#x5F00;&#x9500;&#xFF0C;&#x56E0;&#x4E3A;&#x6D41;&#x91CF;&#x7531; Linux netfilter &#x5904;&#x7406;&#xFF0C; &#x800C;&#x65E0;&#x9700;&#x5728;&#x7528;&#x6237;&#x7A7A;&#x95F4;&#x548C;&#x5185;&#x6838;&#x7A7A;&#x95F4;&#x4E4B;&#x95F4;&#x5207;&#x6362;&#xFF0C; &#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#x4E5F;&#x53EF;&#x80FD;&#x66F4;&#x53EF;&#x9760;&#x3002;</p>
<p>&#x5982;&#x679C; kube-proxy &#x5728; iptables &#x6A21;&#x5F0F;&#x4E0B;&#x8FD0;&#x884C;&#xFF0C;&#x5982;&#x679C;&#x968F;&#x673A;&#x6240;&#x9009;&#x7684;&#x7B2C;&#x4E00;&#x4E2A; Pod &#x6CA1;&#x6709;&#x54CD;&#x5E94;&#xFF0C; &#x5219;&#x8FDE;&#x63A5;&#x4F1A;&#x5931;&#x8D25;&#xFF0C;&#x5728;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4F1A;&#x81EA;&#x52A8;&#x4F7F;&#x7528;&#x5176;&#x4ED6;&#x540E;&#x7AEF; Pod &#x91CD;&#x8BD5; &#x3002;</p>
<p><img src="images/s3.png" alt="s3"></p>
<h4 id="ipvs-&#x4EE3;&#x7406;&#x6A21;&#x5F0F;"><a name="ipvs-&#x4EE3;&#x7406;&#x6A21;&#x5F0F;" class="anchor-navigation-ex-anchor" href="#ipvs-&#x4EE3;&#x7406;&#x6A21;&#x5F0F;"><i class="fa fa-link" aria-hidden="true"></i></a>IPVS &#x4EE3;&#x7406;&#x6A21;&#x5F0F;</h4>
<p>&#x4E0E;&#x5176;&#x4ED6;&#x4EE3;&#x7406;&#x6A21;&#x5F0F;&#x76F8;&#x6BD4;&#xFF0C;IPVS &#x6A21;&#x5F0F;&#x8FD8;&#x652F;&#x6301;&#x66F4;&#x9AD8;&#x7684;&#x7F51;&#x7EDC;&#x6D41;&#x91CF;&#x541E;&#x5410;&#x91CF;&#x3002;&#x4E0E; iptables &#x6A21;&#x5F0F;&#x4E0B;&#x7684; kube-proxy &#x76F8;&#x6BD4;&#xFF0C;IPVS &#x6A21;&#x5F0F;&#x4E0B;&#x7684; kube-proxy &#x91CD;&#x5B9A;&#x5411;&#x901A;&#x4FE1;&#x7684;&#x5EF6;&#x8FDF;&#x8981;&#x77ED;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x540C;&#x6B65;&#x4EE3;&#x7406;&#x89C4;&#x5219;&#x65F6;&#x5177;&#x6709;&#x66F4;&#x597D;&#x7684;&#x6027;&#x80FD;&#x3002;</p>
<p>IPVS &#x63D0;&#x4F9B;&#x4E86;&#x66F4;&#x591A;&#x9009;&#x9879;&#x6765;&#x5E73;&#x8861;&#x540E;&#x7AEF; Pod &#x7684;&#x6D41;&#x91CF;&#x3002; &#x8FD9;&#x4E9B;&#x662F;&#xFF1A;</p>
<ul>
<li><code>rr</code>&#xFF1A;&#x8F6E;&#x66FF;&#xFF08;Round-Robin&#xFF09;</li>
<li><code>lc</code>&#xFF1A;&#x6700;&#x5C11;&#x94FE;&#x63A5;&#xFF08;Least Connection&#xFF09;&#xFF0C;&#x5373;&#x6253;&#x5F00;&#x94FE;&#x63A5;&#x6570;&#x91CF;&#x6700;&#x5C11;&#x8005;&#x4F18;&#x5148;</li>
<li><code>dh</code>&#xFF1A;&#x76EE;&#x6807;&#x5730;&#x5740;&#x54C8;&#x5E0C;&#xFF08;Destination Hashing&#xFF09;</li>
<li><code>sh</code>&#xFF1A;&#x6E90;&#x5730;&#x5740;&#x54C8;&#x5E0C;&#xFF08;Source Hashing&#xFF09;</li>
<li><code>sed</code>&#xFF1A;&#x6700;&#x77ED;&#x9884;&#x671F;&#x5EF6;&#x8FDF;&#xFF08;Shortest Expected Delay&#xFF09;</li>
<li><code>nq</code>&#xFF1A;&#x4ECE;&#x4E0D;&#x6392;&#x961F;&#xFF08;Never Queue&#xFF09;</li>
</ul>
<p><img src="images/s4.png" alt="s4"></p>
<h3 id="service-&#x66B4;&#x9732;&#x591A;&#x7AEF;&#x53E3;"><a name="service-&#x66B4;&#x9732;&#x591A;&#x7AEF;&#x53E3;" class="anchor-navigation-ex-anchor" href="#service-&#x66B4;&#x9732;&#x591A;&#x7AEF;&#x53E3;"><i class="fa fa-link" aria-hidden="true"></i></a>Service &#x66B4;&#x9732;&#x591A;&#x7AEF;&#x53E3;</h3>
<p>&#x5982;&#x679C;&#x8981;&#x5728; Service &#x4E2D;&#x66B4;&#x9732;&#x591A;&#x4E2A;&#x7AEF;&#x53E3;&#xFF0C;&#x5219;&#x6BCF;&#x4E2A;&#x7AEF;&#x53E3;&#x90FD;&#x9700;&#x8981;&#x8BBE;&#x7F6E;&#x4E00;&#x4E2A;&#x540D;&#x5B57;&#x3002;</p>
<pre class="language-"><code class="lang-yaml">    <span class="token key atrule">ports</span><span class="token punctuation">:</span>
    <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> p1
      <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">2323</span>
      <span class="token key atrule">protocol</span><span class="token punctuation">:</span> TCP
      <span class="token key atrule">targetPort</span><span class="token punctuation">:</span> <span class="token number">81</span>
    <span class="token punctuation">-</span> <span class="token key atrule">name</span><span class="token punctuation">:</span> p2
      <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">6666</span>
      <span class="token key atrule">protocol</span><span class="token punctuation">:</span> TCP
      <span class="token key atrule">targetPort</span><span class="token punctuation">:</span> <span class="token number">82</span>
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; &#x75F4;&#x8005;&#x5DE5;&#x826F; 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x6587;&#x6863;&#x6700;&#x540E;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2021-11-17 07:19:29
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: 导读">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="2.endpoint.html" class="navigation navigation-next " aria-label="Next page: 4.2 Endpoint">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"4.1 Kubernetes 网络","level":"1.5.2","depth":2,"next":{"title":"4.2 Endpoint","level":"1.5.3","depth":2,"path":"4.network/2.endpoint.md","ref":"4.network/2.endpoint.md","articles":[]},"previous":{"title":"导读","level":"1.5.1","depth":2,"path":"4.network/README.md","ref":"4.network/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["tbfed-pagefooter","anchor-navigation-ex","mermaid-gb3","insert-logo","chapter-fold","advanced-emoji","github","splitter","alerts","popup","prism","-highlight","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy 痴者工良 2021","modify_label":"文档最后更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"prism":{"lang":{"flow":"typescript","shell":"bash"},"ignore":["mermaid","eval-js"],"css":["prismjs/themes/prism.css"],"js":["prismjs/prism.js","prismjs/components.js","prismjs/components/prism-go.min.js","prismjs/components/prism-yaml.min.js","prismjs/components/prism-bash.min.js","prismjs/components/prism-shell-session.min.js"]},"github":{"url":"https://github.com/whuanle/kubernetes"},"livereload":{},"splitter":{},"search":{},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":false,"showLevel":false},"alerts":{},"advanced-emoji":{"embedEmojis":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"insert-logo":{"style":"background: none; max-height: 50px; min-height: 50px","url":"/images/logo.jpg"}},"theme":"default","author":"痴者工良","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Kubernetes - 痴者工良","language":"zh-hans","links":{"sidebar":{"痴者工良的博客":"https://www.whuanle.cn"}},"gitbook":"*","description":"这是一本关于 Kubernetes 的书，作者 痴者工良"},"file":{"path":"4.network/1.network.md","mtime":"2021-11-16T23:19:29.675Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-11-16T23:21:22.294Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    <script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>

    </body>
</html>

